package com.sywl.orm;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="sys_role")
public class Role {
	
	private Integer roleId;
	private String rolecode;
	private String rolename;
	private List<Account> accounts=new ArrayList<Account>(0);
	
	/*@Override
	public int hashCode() {
		return roleId.hashCode();
	}
	@Override
	public boolean equals(Object obj) {
		if(obj==null){
			return false;
		}
		if(!(obj instanceof Role)){
			return false;
		}
		return this.roleId==((Role)obj).getRoleId();
	}*/
	public Role() {
		// TODO Auto-generated constructor stub
	}
	public Role(String rolecode, String rolename) {
		super();
		this.rolecode = rolecode;
		this.rolename = rolename;
	}
	public Role(String rolecode, String rolename, List<Account> accounts) {
		super();
		this.rolecode = rolecode;
		this.rolename = rolename;
		this.accounts = accounts;
	}
	@Id
	@GeneratedValue
	@Column(name="ROLEID",unique=true,nullable=false)
	public Integer getRoleId() {
		return roleId;
	}
	public void setRoleId(Integer roleId) {
		this.roleId = roleId;
	}
	@Column(name="ROLECODE",unique=true,nullable=false)
	public String getRolecode() {
		return rolecode;
	}
	public void setRolecode(String rolecode) {
		this.rolecode = rolecode;
	}
	@Column(name="ROLENAME",nullable=false)
	public String getRolename() {
		return rolename;
	}
	public void setRolename(String rolename) {
		this.rolename = rolename;
	}
	
//	@JsonBackReference
	@JsonIgnore
	@ManyToMany(mappedBy="roles")
	public List<Account> getAccounts() {
		return accounts;
	}

	public void setAccounts(List<Account> accounts) {
		this.accounts = accounts;
	}
}
